clear
clear matrix
set mem 800m 
use wang&youn-ssq-bits_alliances_clean, clear

//table 1
set more off
xtpcse lnfdiinstock  l.rtf_bit l.atopally l.allybit,  correlation(ar1) hetonly casewise
outreg2 using ally-bit-01, e(rho)label word replace
xtpcse lnfdiinstock  l.rtf_bit l.atopally l.allybit gattwto p_polity2,  correlation(ar1) hetonly casewise
outreg2 using ally-bit-01, e(rho)label word
xtpcse lnfdiinstock  l.rtf_bit l.atopally l.allybit gattwto p_polity2 lngdph wdi_infl pwt_er pwt_openk ihme_ayem lnpop coldwar conflict_in conflict_out distance,  correlation(ar1) hetonly casewise
outreg2 using ally-bit-01, e(rho)label word

//table 2

///kenndy
di (exp(1.1-0.5*(0.04^2))-1)*100
///kennedy se
di 100^2*exp(2*1.01)*(exp(-0.04^2)-exp(-2*0.04^2))
///ci
di 200+1.96*sqrt(120)
di 200-1.96*sqrt(120)

///kennedy
di (exp((1.1+0.94)-0.5*(0.04^2))-1)*100
///kennedy se
di 100^2*exp(2*2.04)*(exp(-0.085^2)-exp(-2*(0.085^2)))
///ci
di 668+1.96*sqrt(4227)
di 668-1.96*sqrt(4227)

///robustness
set more off
areg lnfdiinstock  l.rtf_bit l.atopally l.allybit gattwto p_polity2 lngdph wdi_infl pwt_er pwt_openk ihme_ayem lnpop coldwar conflict_in conflict_out distance,  absorb(year) robust
outreg2 using ally-bit-001, e(rho)label word replace

areg lnfdiinstock  l.rtf_bit l.atopally l.allybit gattwto p_polity2 lngdph wdi_infl pwt_er pwt_openk ihme_ayem lnpop coldwar conflict_in conflict_out distance,  absorb(dyad) robust
outreg2 using ally-bit-001, e(rho) word label

areg lnfdiinstock  l.rtf_bit l.atopally l.allybit gattwto p_polity2 lngdph wdi_infl pwt_er pwt_openk ihme_ayem lnpop coldwar conflict_in conflict_out distance i.year,  absorb(dyad) robust
outreg2 using ally-bit-001, e(rho) word label

xtreg lnfdiinstock  l.rtf_bit l.atopally l.allybit gattwto p_polity2 lngdph wdi_infl pwt_er pwt_openk ihme_ayem lnpop coldwar conflict_in conflict_out  distance, mle vce(boot)
outreg2 using ally-bit-001, e(rho) word label

xtreg lnfdiinstock  l.rtf_bit l.atopally l.allybit gattwto p_polity2 lngdph wdi_infl pwt_er pwt_openk ihme_ayem lnpop coldwar conflict_in conflict_out  distance, re robust 
outreg2 using ally-bit-001, e(rho) word label

reg lnfdiinstock l.lnfdiinstock l.rtf_bit l.atopally l.allybit gattwto p_polity2 lngdph wdi_infl pwt_er pwt_openk ihme_ayem lnpop coldwar conflict_in conflict_out  distance, robust
outreg2 using ally-bit-001, e(rho) word label 
 